From bb9cc8912a0208a1b383ddbd24ecde6c7453e730 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Mon, 12 Mar 2018 13:24:09 -0400 Subject: [PATCH] sysroot: Track whether /run/ostree-booted exists Prep for further work around deployment staging. Closes: #1497 Approved by: jlebon --- src/libostree/ostree-sysroot-private.h | 1 + src/libostree/ostree-sysroot.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/libostree/ostree-sysroot-private.h b/src/libostree/ostree-sysroot-private.h index 3ed6237b..cb4aac9d 100644 --- a/src/libostree/ostree-sysroot-private.h +++ b/src/libostree/ostree-sysroot-private.h @@ -50,6 +50,7 @@ struct OstreeSysroot { GLnxLockFile lock; gboolean loaded; + gboolean ostree_booted; gboolean is_physical; /* TRUE if we're pointed at physical storage root and not a deployment */ GPtrArray *deployments; diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c index 2d12deb6..3294e83d 100644 --- a/src/libostree/ostree-sysroot.c +++ b/src/libostree/ostree-sysroot.c @@ -797,6 +797,16 @@ ostree_sysroot_load_if_changed (OstreeSysroot *self, if (!ensure_repo (self, error)) return FALSE; + /* If we didn't check already, see if we have the global ostree-booted flag; + * we'll use it to sanity check that we found a booted deployment for example. + */ + if (!self->loaded) + { + if (!glnx_fstatat_allow_noent (AT_FDCWD, "/run/ostree-booted", NULL, 0, error)) + return FALSE; + self->ostree_booted = (errno == 0); + } + int bootversion = 0; if (!read_current_bootversion (self, &bootversion, cancellable, error)) return FALSE; @@ -852,6 +862,9 @@ ostree_sysroot_load_if_changed (OstreeSysroot *self, if (!find_booted_deployment (self, deployments, &self->booted_deployment, cancellable, error)) return FALSE; + /* Sanity check; note the converse case is fine */ + if (self->booted_deployment && !self->ostree_booted) + return glnx_throw (error, "Unexpected state: In a booted deployment but no /run/ostree-booted?"); /* Determine whether we're "physical" or not, the first time we initialize */ if (!self->loaded) -- 2.30.2